package com.mMap.service.impl;

import com.mMap.component.RedisComponent;
import com.mMap.entity.config.AppConfig;
import com.mMap.entity.constants.Constants;
import com.mMap.entity.dto.SessionWebUserDto;
import com.mMap.entity.enums.PageSize;
import com.mMap.entity.enums.UserStatusEnum;
import com.mMap.entity.po.MapInfo;
import com.mMap.entity.query.SimplePage;
import com.mMap.entity.query.MapInfoQuery;
import com.mMap.entity.vo.PaginationResultVO;
import com.mMap.exception.BusinessException;
import com.mMap.mappers.MapInfoMapper;
import com.mMap.service.MapInfoService;
import com.mMap.utils.StringTools;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;


/**
 * 思维导图信息 业务接口实现
 */
@Service("mapInfoService")
public class MapInfoServiceImpl implements MapInfoService {

    @Resource
    private MapInfoMapper<MapInfo, MapInfoQuery> mapInfoMapper;


//    @Resource
//    private FileInfoService fileInfoService;

    @Resource
    private AppConfig appConfig;

    @Resource
    private RedisComponent redisComponent;
    private static final Logger logger = LoggerFactory.getLogger(MapInfoServiceImpl.class);

    /**
     * 根据条件查询列表
     */
    @Override
    public List<MapInfo> findListByParam(MapInfoQuery param) {
        return this.mapInfoMapper.selectList(param);
    }

    /**
     * 根据条件查询列表
     */
    @Override
    public Integer findCountByParam(MapInfoQuery param) {
        return this.mapInfoMapper.selectCount(param);
    }

    /**
     * 分页查询方法
     */
    @Override
    public PaginationResultVO<MapInfo> findListByPage(MapInfoQuery param) {
        int count = this.findCountByParam(param);
        int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

        SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
        param.setSimplePage(page);
        List<MapInfo> list = this.findListByParam(param);
        PaginationResultVO<MapInfo> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
        return result;
    }

    /**
     * 新增
     */
    @Override
    public Integer add(MapInfo bean) {
        return this.mapInfoMapper.insert(bean);
    }

    /**
     * 批量新增
     */
    @Override
    public Integer addBatch(List<MapInfo> listBean) {
        if (listBean == null || listBean.isEmpty()) {
            return 0;
        }
        return this.mapInfoMapper.insertBatch(listBean);
    }

    /**
     * 批量新增或者修改
     */
    @Override
    public Integer addOrUpdateBatch(List<MapInfo> listBean) {
        if (listBean == null || listBean.isEmpty()) {
            return 0;
        }
        return this.mapInfoMapper.insertOrUpdateBatch(listBean);
    }

    @Override
    public MapInfo getMapInfoByMapId(String mapId) {
        return this.mapInfoMapper.selectByMapId(mapId);
    }

    @Override
    public Integer updateMapInfoByMapId(MapInfo bean, String mapId) {
        return this.mapInfoMapper.updateByMapId(bean, mapId);
    }

    @Override
    public Integer deleteMapInfoByMapId(String mapId) {
        return this.mapInfoMapper.deleteByMapId(mapId);
    }

}